﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddEdit.aspx.cs" Inherits="CardLogistics.Web.MainPage.PutInCard.PutInBadCard.AddEdit" %>

<%@ Register Src="../../../Controls/WebUserControl_Nav.ascx" TagName="WebUserControl_Nav"
    TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>制卡坏卡入库-编辑</title>
    <link href="../../../css/style.css" rel="stylesheet" type="text/css" />
    <link href="../../../css/selPage.css" rel="stylesheet" type="text/css" />
    <script src="../../../js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="../../../js/valReq.js" type="text/javascript"></script>
    <script src="../../../js/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="../../../js/jquery.tipswindow.2.0.js" type="text/javascript"></script>
    <script type="text/javascript">
        function valReq() {
            var altStr = valid_isempty('BADCARDNO', '坏卡入库单号');
            altStr += valid_isempty('OutStorageNo', '白卡出库单号');
            altStr += valid_isempty('BADCARDDATE', '坏卡入库日期');
            altStr += GetCardInfo();
            altStr += valid_isempty('hf_detailId', '详细信息');
            if (altStr != "") {
                alert(altStr);
                return false;
            }
             else
              return true;
         }

        function GetCardInfo() {
            var Data_value = [];
            var errInfo = ""; //返回错误消息
            var vIndex = 0;
            var cSum = 0; //数量
            var startNo = 0; //开始卡号
            var endNo = 0; //结束卡号
            var StartCardNo = $("input[name=StartCardNo]"); //开始卡号
            var EndCardNo = $("input[name=EndCardNo]"); //  结束卡号
            var ActualNumber = $("input[name=ActualNumber]"); //实际数量
            $("input[name='ActualNumber']").each(function (i, o) {
                if ($(ActualNumber[i]).val() != "0" && $(ActualNumber[i]).val() != "") {
                    Data_value[vIndex] = Trim($(o).val()) + "," + Trim($(StartCardNo[i]).val()) + "," + Trim($(EndCardNo[i]).val()); //明细值
                    cSum += parseInt(Trim($(ActualNumber[i]).val()));
                    startNo = parseInt(Trim($(StartCardNo[i]).val()));
                    endNo = parseInt(Trim($(EndCardNo[i]).val()));

                    vIndex++;
                    if (Trim($(o).val()) == "")
                        errInfo += "第" + vIndex + "行明细不能为空！\n";
                }
            });
            //            alert(Data_value.join(";"));
            $("#hf_detailId").val(Data_value.join(";"));
            document.getElementById("tSum").innerHTML = cSum;

            document.getElementById("hf_CardNum").value = cSum;
            document.getElementById("hf_StartCardNo").value = startNo;
            document.getElementById("hf_EndCardNo").value = endNo;
            return errInfo;
        }

        $(document).ready(function () {

            $("#OutStorageNo").click(function () { //选择白卡出库单号
                $.tipsWindow({
                    ___title: "选择白卡出库单号",
                    ___content: "url:get?../../SelectPage/SelCardOutStorage.aspx",
                    ___width: "1000",
                    ___height: "500",
                    ___drag: "___boxTitle",
                    ___showbg: true
                });
            });

            //输入实际数量汇总
            $("input[name='ActualNumber']").keyup(function () {
                var cNumber = $("input[name=ActualNumber]");
                var csum = 0;
                $("input[name='ActualNumber']").each(function (i, o) {
                    if ($(cNumber[i]).val() != "0" && $(cNumber[i]).val() != "") {
                        csum += parseInt(Trim($(cNumber[i]).val()));
                        if (Trim($(o).text()) == "") {
                            $(o).focus();
                        }
                    }
                });
                document.getElementById("tSum").innerHTML = csum;

            });
        });


        function BindDetailInfo() {
            var cSum = 0; //数量
            var startNo = 0; //开始卡号
            var endNo = 0; //结束卡号
            var cStartCardNo = $("input[name=StartCardNo]"); //开始卡号
            var cEndCardNo = $("input[name=EndCardNo]"); //  结束卡号
            var cActualNumber = $("input[name=ActualNumber]"); //实际数量

            var ids = document.getElementById("hf_detailId").value;
            var str1 = ids.split(";");
            for (var i = 0; i < str1.length; i++) {
                if (str1[i] != "") {
                    $(cActualNumber[i]).val(str1[i].split(",")[0]);
                    $(cStartCardNo[i]).val(str1[i].split(",")[1]);
                    $(cEndCardNo[i]).val(str1[i].split(",")[2]);
                  
                    cSum += parseInt(str1[i].split(",")[0]);
                    startNo = parseInt(str1[i].split(",")[1]);
                    endNo = parseInt(str1[i].split(",")[2]);
                }
            }
            document.getElementById("tSum").innerHTML = cSum;
            document.getElementById("hf_CardNum").value = cSum;
            document.getElementById("hf_StartCardNo").value = startNo;
            document.getElementById("hf_EndCardNo").value = endNo;
        }
        window.onload = function () { BindDetailInfo(); }  
    </script>
</head>
<body>
    <form id="frmFather" runat="server">
    <uc1:WebUserControl_Nav ID="WebUserControl_Nav1" runat="server" />
    <%=TitleName %>
    <input type="hidden" id="hf_detailId" name="hf_detailId" runat="server" />
    <input type="hidden" id="hf_StartCardNo" name="hf_StartCardNo" runat="server" />
    <input type="hidden" id="hf_EndCardNo" name="hf_EndCardNo" runat="server" />
    <input type="hidden" id="hf_CardNum" name="hf_CardNum" runat="server" />
    <table class="theForm" width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td class="titleTxt">
                坏卡入库单号：
            </td>
            <td class="contentTxt">
                <input id="BADCARDNO" runat="server" type="text" class="dfinputNoEmp"  readonly ="readonly"  maxlength="25" />
            </td>
            <td class="titleTxt">
                白卡出库单号：
            </td>
            <td class="contentTxt">
                <input id="OutStorageNo" runat="server" type="text" readonly="readonly" class="dfinputImg"  maxlength="25" />
                <asp:HiddenField ID="hf_OutStorageId" runat="server" />
            </td>
        </tr>
        <tr>
            <td class="titleTxt">
                坏卡入库日期：
            </td>
            <td class="contentTxt">
                <input id="BADCARDDATE" runat="server" type="text" class="Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" />
            </td>
            <td class="titleTxt">
            </td>
            <td class="contentTxt">
            </td>
        </tr>
        <tr>
         <td class="titleTxt">
                备注：
            </td>
            <td  colspan="3">
                <input id="REMARKS" runat="server" type="text" class="dfinput" style="width: 90%;"  maxlength="200"/>
            </td>
        </tr>
        <tr>
            <td colspan="4">
                   <div class="ddetail" style="height: 270px;">
                    <table class="tabledetail" id="tbDetailList">
                        <thead>
                            <tr>
                                <th>
                                    序号
                                </th>
                                <th>
                                    开始卡号
                                </th>
                                <th>
                                    结束卡号
                                </th>
                                <th>
                                    数量
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td width="30px" align="center">
                                    1
                                </td>
                                <td width="130px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="ActualNumber" type="text" value="0" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                            </tr>
                            <tr>
                                <td width="30px" align="center">
                                    2
                                </td>
                                <td width="130px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="9" />
                                </td>
                                <td width="130px">
                                    <input name="ActualNumber" type="text" value="0"  onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                            </tr>
                            <tr>
                                <td width="30px" align="center">
                                    3
                                </td>
                                <td width="130px">
                                    <input name="StartCardNo" type="text"  onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="ActualNumber" type="text" value="0" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                            </tr>
                            <tr>
                                <td width="30px" align="center">
                                    4
                                </td>
                                <td width="130px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="ActualNumber" type="text" value="0" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                            </tr>
                            <tr>
                                <td width="30px" align="center">
                                    5
                                </td>
                                <td width="130px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="ActualNumber" type="text" value="0" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                            </tr>
                            <tr>
                                <td width="30px" align="center">
                                    6
                                </td>
                                <td width="130px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="ActualNumber" type="text" value="0" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                            </tr>
                            <tr>
                                <td width="30px" align="center">
                                    7
                                </td>
                                <td width="130px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="ActualNumber" type="text" value="0" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                            </tr>
                            <tr>
                                <td width="30px" align="center">
                                    8
                                </td>
                                <td width="130px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="ActualNumber" type="text" value="0"  onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                            </tr>
                            <tr>
                                <td width="30px" align="center">
                                    9
                                </td>
                                <td width="130px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="ActualNumber" type="text" value="0" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                            </tr>
                            <tr>
                                <td width="30px" align="center">
                                    10
                                </td>
                                <td width="130px">
                                    <input name="StartCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="EndCardNo" type="text" onkeydown="onlyNum();" maxlength="9"/>
                                </td>
                                <td width="130px">
                                    <input name="ActualNumber" type="text" value="0" onkeydown="onlyNum();" maxlength="9" />
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <table class="tablesum">
                    <tr>
                        <td width="103px">
                            &nbsp;
                        </td>
                        <td width="342px">
                            合计
                        </td>
                        <td width="342px">
                            &nbsp;
                        </td>
                        <td id="tSum" style="text-align: right">
                            0
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr class="btntr">
            <td colspan="4" align="center">
                <asp:Button ID="btn_Add" CssClass="btn" runat="server" Text="保存" OnClientClick="return valReq();"
                    OnClick="btn_Add_Click" />
                <input type="button" class="btn" value="返回" onclick="javascript:history.go(-1);" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
